package com.lsh.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author ：LiuShihao
 * @date ：Created in 2020/12/16 10:17 下午
 * @desc ：看阿里巴巴开发手册并发编程这块有一条：线程池不允许使用Executors去创建，而是通过ThreadPoolExecutor的方式手动创建。
 */
public class NewFixedThreadPool {
    public static void main(String[] args) {
        //1.创建可缓存的线程池，可重复利用
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            int finalTemp = i;
            executorService.execute(() ->{
                System.out.println(Thread.currentThread().getName()+": 第"+ finalTemp +"个线程");
            });

        }
    }

}
